Skip to content

Fix wrapt 2.x compatibility: rename moduletarget in wrap_function_wrapper call - #264

Open
joetanx wants to merge 2 commits into
microsoft:mainfrom
joetanx:main
Open

Fix wrapt 2.x compatibility: rename moduletarget in wrap_function_wrapper call#264
joetanx wants to merge 2 commits into
microsoft:mainfrom
joetanx:main

Conversation

@joetanx

@joetanx joetanx commented Jul 3, 2026

Copy link
Copy Markdown

Problem

CustomLangChainInstrumentor._instrument() calls wrapt.wrap_function_wrapper() using the module keyword argument, which was [removed in wrapt 2.0](https://github.com/GrahamDumpleton/wrapt/releases/tag/2.0.0) and renamed to target. This forces downstream consumers to pin wrapt<2, which conflicts with other packages that already require wrapt>=2.

# Before (breaks on wrapt >= 2.0)
wrap_function_wrapper(
    module="langchain_core.callbacks",
    name="BaseCallbackManager.__init__",
    wrapper=_BaseCallbackManagerInit(self._tracer),
)

Fix

Use the target parameter instead. The new combined-path syntax ("module:qualname") is supported in both wrapt 1.x (≥1.16) and 2.x, so this change is backwards-compatible.

# After (works on wrapt 1.x and 2.x)
wrap_function_wrapper(
    target="langchain_core.callbacks",
    name="BaseCallbackManager.__init__",
    wrapper=_BaseCallbackManagerInit(self._tracer),
)

Impact

  • Removes the need for consumers to pin wrapt<2
  • No behavioral change — only the keyword argument name changes
  • Backwards-compatible with wrapt ≥1.16

@joetanx
joetanx requested a review from a team as a code owner July 3, 2026 00:19
Copilot AI review requested due to automatic review settings July 3, 2026 00:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the LangChain observability instrumentor to be compatible with wrapt 2.x by adjusting how wrapt.wrap_function_wrapper() is invoked when wrapping BaseCallbackManager.__init__.

Changes:

  • Switches from the removed module= keyword argument to target= in the wrap_function_wrapper call.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 00:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines 74 to 78
wrap_function_wrapper(
module="langchain_core.callbacks",
target="langchain_core.callbacks",
name="BaseCallbackManager.__init__",
wrapper=_BaseCallbackManagerInit(self._tracer),
)

@rbrighenti Rick Brighenti (rbrighenti) Jul 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolving this conversation because Copilot is right here. I don't think having target here is actually compatible with any 1.x version. We'll need to check if using just positional arguments would work without issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants